import java.util.Stack;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */
public class Main {
    public static boolean isValid(String s) {

        Stack<Character> stack = new Stack<>();

        for(int i =0;i < s.length();i++){
            Character x = s.charAt(i);
            if(x.equals('[') || x.equals('(') || x.equals('{')){
                stack.push(x);
            }else{
                if(stack.empty())
                    return false;
                Character ch = stack.peek();

                if(x == ')' && ch == '(' || ch == '{' && x == '}' || ch == '[' && x == ']'){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }

        if(!stack.empty()) return false;

        return true;

    }

    public int evalRPN(String[] tokens) {

        Stack<Integer> stack  = new Stack<>();

        for(String x : tokens){

            if(isNumber(x)){
                stack.push(Integer.parseInt(x));
            }else{
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(x){
                    case "+":
                        stack.push(num1 + num2);
                        break;
                    case "-":
                        stack.push(num1 - num2);
                        break;
                    case "*":
                        stack.push(num1 * num2);
                        break;
                    case "/":
                        stack.push(num1 / num2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isNumber(String x){

        if(x.equals("+") || x.equals("-") || x.equals("*") || x.equals("/"))
            return false;

        return true;
    }


    public static void main(String[] args) {
         String s = "()";
        System.out.println(isValid(s));
    }
}